package com.zl.zsk.pojo.vo;

import com.zl.zsk.constant.RetCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {
    private Object data;
    private String msg;
    private boolean success;
    private int code;

    private static final boolean FAIL = false;
    private static final boolean SUCCESS = true;
    /**
     * 成功
     * @return
     */
    public static Result success(){
        return success(null);
    }

    /**
     * 成功
     * @param object
     * @return
     */
    public static Result success(Object object){
        RetCode success = RetCode.SUCCESS;
        return new Result(object,success.getMsg(),SUCCESS,success.getCode());
    }

    /**
     * 失败
     * @param msg
     * @param code
     * @return
     */
    public static Result failure(String msg,int code){
        return new Result(null,msg,FAIL,code);
    }

    /**
     * 权限不足
     * @return
     */
    public static Result permissionDeny(){
        RetCode authDeny = RetCode.AUTH_DENY;
        return new Result(null,authDeny.getMsg(),FAIL,authDeny.getCode());
    }

    /**
     * 未登录
     * @return
     */
    public static Result loginFail(){
        RetCode notlogin = RetCode.NOTLOGIN;
        return new Result(null,notlogin.getMsg(),FAIL,notlogin.getCode());
    }

    public static Result bizFault(){
        RetCode businesserror = RetCode.BUSINESSERROR;
        return new Result(null,businesserror.getMsg(),FAIL,businesserror.getCode());
    }

    public static Result noRecord(){
        RetCode nulldata = RetCode.NULLDATA;
        return new Result(null,nulldata.getMsg(),FAIL,nulldata.getCode());
    }

    public static Result notFound(){
        RetCode notFound = RetCode.NOT_FOUND;
        return new Result(null,notFound.getMsg(),FAIL,notFound.getCode());
    }
}
